#include<iostream>
#include<vector>
#include<pthread.h>
#include <unistd.h>

using namespace std;

#define NUM 10

struct threadData
{
    string tid;
    string threadname;
};

void InitThreadData(threadData *td,int number,pthread_t tid)
{
    td->threadname="thread-"+to_string(number);// thread-0

    char buffer[128];
    snprintf(buffer,sizeof(buffer),"0x%x",tid);
    td->tid=buffer;
}

void *threadRoutine(void *args)
{
    threadData *td=static_cast<threadData *>(args);
    int i=0;
    while(i<10)
    {
        cout<<"pid: "<<getpid()<<",tid:"<<td->tid<<",threadname:"<<td->threadname<<endl;
        sleep(1);
        i++;
    }
    
    delete td;
    return nullptr;
}

int main()
{
    vector<pthread_t> tids;
    for(int i=0;i<NUM;i++)
    {
        /*threadData td;
        td.threadname=;
        td.tid=;*/

        pthread_t tid;
        threadData *td=new threadData;
        InitThreadData(td,i,tid);

        pthread_create(&tid,nullptr,threadRoutine,td);
        tids.push_back(tid);
        sleep(1);
    }

    for(int i=0;i<tids.size();i++)
    {
        pthread_join(tids[i],nullptr);
    }

    return 0;
}